using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;
using SharpCore.Utilities;

namespace Dating.DA
{
	public class MemberProfileDA
	{
		#region Fields

		protected string connectionStringName;

		#endregion

		#region Constructors
		public MemberProfileDA()
		{
		}

		public MemberProfileDA(string connectionStringName)
		{
			ValidationUtility.ValidateArgument("connectionStringName", connectionStringName);

			this.connectionStringName = connectionStringName;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Saves a record to the MemberProfile table.
		/// </summary>
		public  int Insert(MemberProfile memberProfile)
		{
			ValidationUtility.ValidateArgument("memberProfile", memberProfile);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", memberProfile.TenantID),
				new SqlParameter("@UserName", memberProfile.UserName),
				new SqlParameter("@Passwrd", memberProfile.Passwrd),
				new SqlParameter("@EmailId", memberProfile.EmailId),
				new SqlParameter("@FirstName", memberProfile.FirstName),
				new SqlParameter("@LastName", memberProfile.LastName),
				new SqlParameter("@DOB", memberProfile.DOB),
				new SqlParameter("@Height", memberProfile.Height),
				new SqlParameter("@GeneralBuild", memberProfile.GeneralBuild),
				new SqlParameter("@HairColor", memberProfile.HairColor),
				new SqlParameter("@EyeColor", memberProfile.EyeColor),
				new SqlParameter("@Ethnicity", memberProfile.Ethnicity),
				new SqlParameter("@SmokingPreference", memberProfile.SmokingPreference),
				new SqlParameter("@Looks", memberProfile.Looks),
				new SqlParameter("@Occupation", memberProfile.Occupation),
				new SqlParameter("@Income", memberProfile.Income),
				new SqlParameter("@RelationshipExpectation", memberProfile.RelationshipExpectation),
				new SqlParameter("@MySelf", memberProfile.MySelf),
				new SqlParameter("@Seeking", memberProfile.Seeking),
				new SqlParameter("@MartialStatus", memberProfile.MartialStatus),
				new SqlParameter("@NumberOfChildren", memberProfile.NumberOfChildren),
				new SqlParameter("@LivingAtHome", memberProfile.LivingAtHome),
				new SqlParameter("@Religion", memberProfile.Religion),
				new SqlParameter("@Pet", memberProfile.Pet),
				new SqlParameter("@Country", memberProfile.Country),
				new SqlParameter("@State", memberProfile.State),
				new SqlParameter("@City", memberProfile.City),
				new SqlParameter("@Postcode", memberProfile.Postcode),
				new SqlParameter("@Wallpaper", memberProfile.Wallpaper),
				new SqlParameter("@Icon", memberProfile.Icon),
				new SqlParameter("@CreatedOn", memberProfile.CreatedOn),
				new SqlParameter("@LastLoginOn", memberProfile.LastLoginOn),
				new SqlParameter("@IsLoggedIn", memberProfile.IsLoggedIn)
			};

			memberProfile.ProfileID = Convert.ToInt32(SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "MemberProfileInsert", parameters));
			return memberProfile.ProfileID;
		}

		/// <summary>
		/// Updates a record in the MemberProfile table.
		/// </summary>
		public  int Update(MemberProfile memberProfile)
		{
			ValidationUtility.ValidateArgument("memberProfile", memberProfile);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", memberProfile.ProfileID),
				new SqlParameter("@TenantID", memberProfile.TenantID),
				new SqlParameter("@UserName", memberProfile.UserName),
				new SqlParameter("@Passwrd", memberProfile.Passwrd),
				new SqlParameter("@EmailId", memberProfile.EmailId),
				new SqlParameter("@FirstName", memberProfile.FirstName),
				new SqlParameter("@LastName", memberProfile.LastName),
				new SqlParameter("@DOB", memberProfile.DOB),
				new SqlParameter("@Height", memberProfile.Height),
				new SqlParameter("@GeneralBuild", memberProfile.GeneralBuild),
				new SqlParameter("@HairColor", memberProfile.HairColor),
				new SqlParameter("@EyeColor", memberProfile.EyeColor),
				new SqlParameter("@Ethnicity", memberProfile.Ethnicity),
				new SqlParameter("@SmokingPreference", memberProfile.SmokingPreference),
				new SqlParameter("@Looks", memberProfile.Looks),
				new SqlParameter("@Occupation", memberProfile.Occupation),
				new SqlParameter("@Income", memberProfile.Income),
				new SqlParameter("@RelationshipExpectation", memberProfile.RelationshipExpectation),
				new SqlParameter("@MySelf", memberProfile.MySelf),
				new SqlParameter("@Seeking", memberProfile.Seeking),
				new SqlParameter("@MartialStatus", memberProfile.MartialStatus),
				new SqlParameter("@NumberOfChildren", memberProfile.NumberOfChildren),
				new SqlParameter("@LivingAtHome", memberProfile.LivingAtHome),
				new SqlParameter("@Religion", memberProfile.Religion),
				new SqlParameter("@Pet", memberProfile.Pet),
				new SqlParameter("@Country", memberProfile.Country),
				new SqlParameter("@State", memberProfile.State),
				new SqlParameter("@City", memberProfile.City),
				new SqlParameter("@Postcode", memberProfile.Postcode),
				new SqlParameter("@Wallpaper", memberProfile.Wallpaper),
				new SqlParameter("@Icon", memberProfile.Icon),
				new SqlParameter("@CreatedOn", memberProfile.CreatedOn),
				new SqlParameter("@LastLoginOn", memberProfile.LastLoginOn),
				new SqlParameter("@IsLoggedIn", memberProfile.IsLoggedIn)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberProfileUpdate", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberProfile table by its primary key.
		/// </summary>
		public  int Delete(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberProfileDelete", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberProfile table by a foreign key.
		/// </summary>
		public  int DeleteAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberProfileDeleteAllByTenantID", parameters));
		}

		/// <summary>
		/// Selects a single record from the MemberProfile table.
		/// </summary>
		public  MemberProfile Select(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberProfileSelect", parameters))
			{
				if (dataReader.Read())
				{
					return MakeMemberProfile(dataReader);
				}
				else
				{
					return null;
				}
			}
		}

		/// <summary>
		/// Selects all records from the MemberProfile table.
		/// </summary>
		public  List<MemberProfile> SelectAll(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)
			};
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberProfileSelectAll", parameters))
			{
				List<MemberProfile> memberProfileList = new List<MemberProfile>();
				while (dataReader.Read())
				{
					MemberProfile memberProfile = MakeMemberProfile(dataReader);
					memberProfileList.Add(memberProfile);
				}

				return memberProfileList;
			}
		}

		/// <summary>
		/// Selects all records from the MemberProfile table by a foreign key.
		/// </summary>
		public  List<MemberProfile> SelectAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberProfileSelectAllByTenantID", parameters))
			{
				List<MemberProfile> memberProfileList = new List<MemberProfile>();
				while (dataReader.Read())
				{
					MemberProfile memberProfile = MakeMemberProfile(dataReader);
					memberProfileList.Add(memberProfile);
				}

				return memberProfileList;
			}
		}

		/// <summary>
		/// Creates a new instance of the MemberProfile class and populates it with data from the specified SqlDataReader.
		/// </summary>
		protected  MemberProfile MakeMemberProfile(SqlDataReader dataReader)
		{
			MemberProfile memberProfile = new MemberProfile();
			memberProfile.ProfileID = SqlClientUtility.GetInt32(dataReader, "ProfileID", 0);
			memberProfile.TenantID = SqlClientUtility.GetInt32(dataReader, "TenantID", 0);
			memberProfile.UserName = SqlClientUtility.GetString(dataReader, "UserName", String.Empty);
			memberProfile.Passwrd = SqlClientUtility.GetString(dataReader, "Passwrd", String.Empty);
			memberProfile.EmailId = SqlClientUtility.GetString(dataReader, "EmailId", String.Empty);
			memberProfile.FirstName = SqlClientUtility.GetString(dataReader, "FirstName", String.Empty);
			memberProfile.LastName = SqlClientUtility.GetString(dataReader, "LastName", String.Empty);
			memberProfile.DOB = SqlClientUtility.GetDateTime(dataReader, "DOB", DateTime.Now);
			memberProfile.Height = SqlClientUtility.GetString(dataReader, "Height", String.Empty);
			memberProfile.GeneralBuild = SqlClientUtility.GetString(dataReader, "GeneralBuild", String.Empty);
			memberProfile.HairColor = SqlClientUtility.GetString(dataReader, "HairColor", String.Empty);
			memberProfile.EyeColor = SqlClientUtility.GetString(dataReader, "EyeColor", String.Empty);
			memberProfile.Ethnicity = SqlClientUtility.GetString(dataReader, "Ethnicity", String.Empty);
			memberProfile.SmokingPreference = SqlClientUtility.GetString(dataReader, "SmokingPreference", String.Empty);
			memberProfile.Looks = SqlClientUtility.GetString(dataReader, "Looks", String.Empty);
			memberProfile.Occupation = SqlClientUtility.GetString(dataReader, "Occupation", String.Empty);
			memberProfile.Income = SqlClientUtility.GetString(dataReader, "Income", String.Empty);
			memberProfile.RelationshipExpectation = SqlClientUtility.GetString(dataReader, "RelationshipExpectation", String.Empty);
			memberProfile.MySelf = SqlClientUtility.GetString(dataReader, "MySelf", String.Empty);
			memberProfile.Seeking = SqlClientUtility.GetString(dataReader, "Seeking", String.Empty);
			memberProfile.MartialStatus = SqlClientUtility.GetString(dataReader, "MartialStatus", String.Empty);
			memberProfile.NumberOfChildren = SqlClientUtility.GetString(dataReader, "NumberOfChildren", String.Empty);
			memberProfile.LivingAtHome = SqlClientUtility.GetString(dataReader, "LivingAtHome", String.Empty);
			memberProfile.Religion = SqlClientUtility.GetString(dataReader, "Religion", String.Empty);
			memberProfile.Pet = SqlClientUtility.GetString(dataReader, "Pet", String.Empty);
			memberProfile.Country = SqlClientUtility.GetString(dataReader, "Country", String.Empty);
			memberProfile.State = SqlClientUtility.GetString(dataReader, "State", String.Empty);
			memberProfile.City = SqlClientUtility.GetString(dataReader, "City", String.Empty);
			memberProfile.Postcode = SqlClientUtility.GetString(dataReader, "Postcode", String.Empty);
			memberProfile.Wallpaper = SqlClientUtility.GetString(dataReader, "Wallpaper", String.Empty);
			memberProfile.Icon = SqlClientUtility.GetString(dataReader, "Icon", String.Empty);
			memberProfile.CreatedOn = SqlClientUtility.GetDateTime(dataReader, "CreatedOn", DateTime.Now);
			memberProfile.LastLoginOn = SqlClientUtility.GetDateTime(dataReader, "LastLoginOn", DateTime.Now);
			memberProfile.IsLoggedIn = SqlClientUtility.GetString(dataReader, "IsLoggedIn", String.Empty);

			return memberProfile;
		}

		#endregion
	}
}
